package models

type House struct {
	Id     int     `json:"id"`
	Name   string  `json:"name"`
	MenHao int     `json:"menHao"`
	Types  string  `json:"types"`
	Price  float64 `json:"price"`
	Area   int     `json:"area"`
}

func MysqlList(page int, pageSize int, name string) ([]House, int64, error) {
	var house []House
	var total int64
	var query = DB.Model(&House{})
	if name != "" {
		query = query.Where("name like ?", "%"+name+"%")
	}
	if err = query.Order(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&house).Error; err != nil {
		return nil, 0, err
	}
	return house, total, nil
}
